<template>
  <card ref="Card">
    <el-table :data="formData">
      <el-table-column prop="begin" label="开始号码">
        <template slot-scope="scope">
          <span>{{add0(scope.row.begin)}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="end" label="结束号码">
        <template slot-scope="scope">
          <span>{{add0(scope.row.end)}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="sendToUserName" label="分配网点"/>
      <el-table-column prop="createTime" label="分配时间">
        <template slot-scope="scope">
          <span>{{scope.row.createTime | formatDateTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="150">
        <template slot-scope="scope">
          <el-button type="warning" @click.stop="withdraw(scope.row)">撤回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination ref="Pagination" @update="getData"/>
  </card>
</template>

<script>
  import {pageRecordsApi, recallApi} from "@/api/order/number";

  export default {
    name: "Withdraw",
    data() {
      return {
        formData: []
      }
    },
    mounted() {
      this.getData()
    },
    methods: {
      add0(value) {
        value = value + '';
        while (value.length < 13) {
          value = '0' + value;
        }
        return value
      },
      getData() {
        let pagination = this.$refs.Pagination;
        let param = {
          current: pagination.current,
          size: pagination.size
        };
        this.$refs.Card.start();
        pageRecordsApi(param).then(result => {
          let response = result.resultParam.recordsPage;
          this.formData = response.records;
          pagination.total = response.total;
          this.$refs.Card.stop();
        })
      },
      withdraw(row) {
        this.$msgBox('确认撤回？').then(() => {
          recallApi({id: row.id}).then(() => {
            this.getData()
          })
        })
      }
    }
  }
</script>
